package com.example.demo1.controller;

import com.example.demo1.entity.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mvc")
public class TestController {

    //http://localhost:8080/mvc/user?username=%E5%BC%A0%E4%B8%89
    @RequestMapping("/user")
    public String user(@RequestParam String username,@RequestParam String password){
        System.out.println("username"+username);
        System.out.println("password"+password);
        return "success";
    }

    //http://localhost:8080/mvc/user/1/zhangsan
    @RequestMapping(value = "/user/{id}/{name}")
    public String user2(@PathVariable Integer id,
                        @PathVariable String name,
                        @RequestParam Integer age){
        System.out.println("id="+id);
        System.out.println("name="+name);
        System.out.println("age="+age);
        return "success";
    }

    @PostMapping("/login")
    public String login(@RequestBody User user){
        String username = user.getUsername();
        String password = user.getPassword();
        Integer code = user.getCode();
        System.out.println("code:"+code);
        if (username.equals("")){
            return "用户名错误";
        }

        if (password.equals("123456")){
            return "success";
        }else {
            return "密码错误";
        }
    }

    @PostMapping("/add")
    public String add(@RequestParam String username,
                      @RequestParam String password){
        System.out.println(username);
        System.out.println(password);
        return "success";
    }


    @PostMapping("/add2")
    public String add2(User user){
        String username = user.getUsername();
        String password = user.getPassword();
        Integer code = user.getCode();
        return "success";
    }


}
